package com.example.helloword.controller;

import com.example.helloword.entity.User;
import org.springframework.web.bind.annotation.*;
//报错status=400，客户端的问题

@RestController
public class ParamsController {
    @RequestMapping(value = "/getTest1",method = RequestMethod.GET)
    public String getTest1(){
        return "GET请求";
    }
    @RequestMapping(value = "/getTest2",method = RequestMethod.GET)
    public String getTest2(String nickname , String phone){
        System.out.println("nickname:"+nickname);
        System.out.println("phone:"+phone);
        return "GET请求" + nickname + phone;
    }
    //required = false这个参数传不传递都可以，但如果是默认的话@RequestParam必须传递参数
    @RequestMapping(value = "/getTest3",method = RequestMethod.GET)
    public String getTest3(@RequestParam(value = "nickname",required = false)String name){
        System.out.println("nickname:"+name);
        return "GET请求";
    }

    @RequestMapping(value = "/postTest1",method = RequestMethod.POST)
    public String postTest1(){
        return "Post 请求";
    }
    @RequestMapping(value = "/postTest2",method = RequestMethod.POST)
    public String postTest2(String username ,String password){
        System.out.println("username:"+username);
        System.out.println("password:"+password);
        return "Post 请求";
    }

    @RequestMapping(value = "/postTest3",method = RequestMethod.POST)
    public String postTest3(User user){
        System.out.println(user);
        return "Post 请求";
    }
//    传递形式为json形式，要加上注解@RequestBody
    @RequestMapping(value = "/postTest4",method = RequestMethod.POST)
    public String postTest4(@RequestBody User user){
        System.out.println(user);
        return "Post 请求";
    }
    @GetMapping("/test/**")
    public String test(){
        return "通配符请求";
    }
}
